<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-button v-if="$hasPermission('scenic:workorder:delete')" type="danger" @click="deleteHandle(id)">{{
            $t("deleteBatch")
          }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('scenic:workorder:export')" type="primary" @click="exportHandle()">导出</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="complainantId"
          label="投诉对象"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="联系电话"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="reply"
          label="处理结果"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <!--<el-table-column-->
        <!--prop="pic"-->
        <!--label="图片"-->
        <!--header-align="center"-->
        <!--min-width="120"-->
        <!--align="center"-->
        <!--&gt;-->
        <!--<template slot-scope="scope">-->
        <!--<img :src="scope.row.pic" style="width:70px;height:70px" />-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column
          prop="complainantType"
          label="投诉类型"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ types[scope.row.complainantType] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="state"
          label="状态 "
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ types2[scope.row.state] }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="创建时间"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="
                $hasPermission('scenic:workorder:update') && scope.row.state == 0
              "
              @click="
                disabled = false;
                addOrUpdateHandle(scope.row.id);
              "
              >编辑</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="
                $hasPermission('scenic:workorder:info') && scope.row.state == 1
              "
              @click="
                disabled = true;
                addOrUpdateHandle(scope.row.id);
              "
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
        :disabled="disabled"
        @changeDisabled="disabled = false"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./workOrder-add-or-update2";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      disabled: false,
      mixinViewModuleOptions: {
        getDataListURL: "/scenic/workOrder/page",
        getDataListIsPage: true,
        deleteURL: "/scenic/workOrder",
        deleteIsBatch: true,
        exportURL: "/scenic/workOrder/export",
      },
      types: [
        "功能故障",
        "景区意见",
        "产品建议",
        "预订咨询",
        "订单咨询",
        "其他",
      ],
      types2: ["派单中", "已结束"],
      dataForm: {
        head: this.$store.state.user.id,
      },
    };
  },
  components: {
    AddOrUpdate,
  },
  created() {},
  methods: {
    end(complaintld, id) {
      this.$confirm("确定该操作？", this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning",
      })
        .then(() => {
          this.$http
            .get(`/scenic/workOrder/updateStateByld`, {
              params: {
                complaintld: complaintld,
                id: id,
              },
            })
            .then((res) => {
              if (res.data.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
            });
        })
        .catch(() => {});
    },
    reply(id) {
      this.$prompt("请输入回复内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          this.$http
            .put("/scenic/complaintrecommendation/reply", {
              id: id,
              reply: value,
            })
            .then((res) => {
              this.$message({
                type: "info",
                message: "取消输入",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
  },
};
</script>
